// src/renderer/ipc-bridge.ts
import { App } from 'vue'
import type { IpcBridge } from '@/types/ipc'

declare global {
  interface Window {
    ipc: IpcBridge
  }
}

const ipcBridge: IpcBridge = {
  request(api, data) {
    return window.ipc.request(api, data)
  },
  send(channel, payload) {
    window.ipc.send(channel, payload)
  },
  on(channel, callback) {
    return window.ipc.on(channel, callback)
  },
  once(channel, callback) {
    window.ipc.once(channel, callback)
  },
  off(channel, callback) {
    window.ipc.off(channel, callback)
  }
}

export default {
  install(app: App) {
    app.config.globalProperties.$ipc = ipcBridge
  },
  ...ipcBridge
}
